package cn.wolfcode.luowowo2.mgrsite.web.controller;

import cn.wolfcode.luowowo2.mgrsite.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Albert on 2019/7/9.
 */
@Controller
@RequestMapping("uploadImg_ck")
public class UploadCkController {
    @Value("${file.path}")
    private String realPath;

    @RequestMapping("")
    @ResponseBody
    public Map<String,Object> uploadImg(MultipartFile upload){
        HashMap<String,Object> map = new HashMap<>();
        try{
            String url = UploadUtil.upload(upload, realPath);
            //map.put("status",1);
            map.put("uploaded",1);
            map.put("url","/"+ url);
        }catch (Exception e){
            e.printStackTrace();
            //map.put("status",0);
            map.put("uploaded",0);
            map.put("msg","上传失败");
        }
        return map;
    }
}
